【VBA研究】64位系统下无法用ScriptControl控件解析JSon数据
lzzzl:
Option Explicit
Private objHtml As Object
Private objWin As Object
Private Sub init()
If objHtml Is Nothing Then
Set objHtml = CreateObject("HTMLFile")
Set objWin = objHtml.parentWindow
End If
End Sub
'eg set person = new clsScript
'?person.parseAndGet("{name: ""zhang3"", age: 24}", "name")
Public Sub parse(ByVal jsonStr As String)
init
'解析结果保存到脚本全局变量以备后用
objWin.execScript "window.x=" & jsonStr & ";"
End Sub
Public Function parseJsonAndGetProperty(ByVal jsonStr As String, ByVal nestedPropertyName As String) As String
'parseJsonAndGetProperty = objWin.Eval("window.x=" & jsonStr & ";window.x." & nestedPropertyName)
parse jsonStr
parseJsonAndGetProperty = getProperty(nestedPropertyName)
End Function
Public Function getProperty(ByVal nestedPropertyName As String) As String
getProperty = objWin.Eval("window.x." & nestedPropertyName)
End Function
|